package com.ede.roverhu.simplebackstage.Utils;

import android.app.Activity;
import android.content.Context;
import android.widget.Toast;

/**
 * Created by Rover on 2016/10/7 .
 * Email 357319517@qq.com
 */
public class ToastUtils {

    /**
     * 子线程显示Toast
     *
     * @param activity
     * @param text
     */
    public static void show(final Activity activity, final String text) {
        if (Thread.currentThread().getName().equalsIgnoreCase("main")) {
            Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
        } else {
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(activity, text, Toast.LENGTH_SHORT).show();
                }
            });
        }
    }

    /**
     * 子线程显示Toast
     *
     * @param activity
     * @param text
     * @param len      时长
     */
    public static void show(final Activity activity, final String text, final int len) {
        if (Thread.currentThread().getName().equalsIgnoreCase("main")) {
            Toast.makeText(activity, text, len).show();
        } else {
            activity.runOnUiThread(new Runnable() {
                @Override
                public void run() {
                    Toast.makeText(activity, text, len).show();
                }
            });
        }
    }

    /**
     * 用context显示
     *
     * @param Context
     * @param text
     * @param len      时长
     */
    public static void show(Context Context, String text) {
        Toast.makeText(Context, text, Toast.LENGTH_SHORT).show();
    }
}
